package com.todo.event.activity.iface.backend.request;

import com.todo.common.common.entity.CurrentStaff;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.common.utils.StringUtils;
import com.todo.event.activity.iface.backend.common.ActivityExecuteInfo;
import com.todo.event.activity.iface.backend.common.ActivityRule;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/1/10 22:33
 * @description
 */
@Data
public class InsertEventActivityReq {

private CurrentStaff _staff;

    @Schema(title = "活动名称", description = "活动名称")
    private String name;

    @Schema(title = "活动描述", description = "活动描述")
    private String desc;

    @Schema(title = "业务线", description = "业务线")
    private Integer businessLine;

    @Schema(title = "决策id", description = "决策id")
    private Long decisionId;

    @Schema(title = "执行规则", description = "执行规则")
    private ActivityRule activityRule;

    @Schema(title = "执行信息", description = "执行信息")
    private List<ActivityExecuteInfo> executeInfoBOList;

    @Schema(title = "开始时间", description = "开始时间")
    private Date startTime;

    @Schema(title = "结束时间", description = "结束时间")
    private Date endTime;

    public boolean baseCheck() {
        if (StringUtils.isBlank(name) || businessLine == null || decisionId == null || startTime == null || endTime == null) {
            return false;
        }
        if (activityRule == null || !activityRule.baseCheck() || CollectionUtils.isEmpty(executeInfoBOList)) {
            return false;
        }
        for (ActivityExecuteInfo executeInfoBO : executeInfoBOList) {
            if (!executeInfoBO.baseCheck()) {
                return false;
            }
        }
        if (startTime.after(endTime)) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR, "开始时间不能大于结束时间");
        }
        return true;
    }
}
